﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace RazorGenerateCodes.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult About()
        {
            ViewBag.Message = "Your application description page.";

            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }

        public void Gen()
        {
            var template = new ViewGenerator()
            {
                Type = typeof(Person)
            };

            var viewContent = template.TransformText();

            var path = Server.MapPath("~");
            var viewDirPath = Path.Combine(path, "views", "Person");
            if (!Directory.Exists(viewDirPath))
            {
                Directory.CreateDirectory(viewDirPath);
            }

            var viewFilePath =  Path.Combine(path, "views", "Person", "Create.cshtml");

            System.IO.File.WriteAllText(viewFilePath, viewContent);
           
        }
    }

    public class Person
    {
        public int Age { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public DateTime BirthDate { get; set; }
        public bool LikesMusic { get; set; }
        public IList<Skill> Skills { get; set; }
    }

    public class Skill {
        public string SkillName { get; set; }

    }
}